#!/usr/bin/env python
# -*- coding:utf-8 -*-

"""
@author zyx
@since 2022/2/27 19:01
@file: c04_redis案例.py
"""

import redis

# 创建链接对象
# conn = redis.Redis(host='127.0.0.1', port=6379, password='123321')
# 官方建议使用StrictRedis
#   db: 指定数据库,默认为0
#   decode_responses: 默认未false, 返回的是字节数组; 指定为true, 则返回字符串
conn = redis.StrictRedis(host='127.0.0.1', port=6379, password='123321', decode_responses=True)

# 插入数据
# result = conn.sadd('class','num4')
# print(result)

# result = conn.lpush('hobby','haha')
# print(result)

# 查询set集合里的数据
# print(conn.smembers('class'))

print(conn.hgetall('tujian'))

conn.close()
